<?php
//包含数据库配置文件
include '../../public/dbconfig.php';
//包含函数库文件
include '../../public/functions.php';
//调用函数 链接数据库
$link = con();

//接收友链标题
$username = $_POST['username'];
//接收友链地址
$url = $_POST['url'];
//接收友链描述
$keywords = $_POST['keywords'];
//判断友链标题是否为空
if(empty($username)){
	echo '<script>alert("友链名称不能为空");window.location.href="add.php";</script>';
	exit;
}
//判断友链地址是否为空
if(empty($url)){
	echo '<script>alert("友链地址不能为空");window.location.href="add.php";</script>';
	exit;
}
//判断友链描述是否为空
if(empty($keywords)){
	echo '<script>alert("友链描述不能为空");window.location.href="add.php";</script>';
	exit;
}
//判断用户是否上传logo
if($_FILES['logo']['error'] != 4){
	$logo = upload('logo','../../home/images/');
	suofang('../../home/images/'.$logo,130,65);
}

//准备sql
$sql = "insert into friends(username,url,keywords,logo) values ('{$username}','{$url}','{$keywords}','{$logo}')";
//执行sql
$res = mysqli_query($link, $sql);
//判断执行结果
if($res){
	echo '<script>alert("添加成功");window.location.href="list.php";</script>';
}else{
	echo '<script>alert("添加失败");window.location.href="add.php";</script>';
}
//关闭数据库链接
mysqli_close($link);